package xyf.p02.stack_queue;

import java.util.Stack;

/**
 * ClassName: P0155_MinStack
 * Description:
 * Author: xyf
 * Date: 9/3/22 6:21 PM
 * Version: 1.0
 **/
public class P0155_MinStack
{
    class MinStack
    {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> help = new Stack<>();

        public MinStack()
        {

        }

        public void push(int val)
        {
            stack.push(val);

            if (help.isEmpty())
            {
                help.push(val);
                return;
            }

            if (val <= help.peek())
            {
                help.push(val);
            }
            else
            {
                help.push(help.peek());
            }
        }

        public void pop()
        {
            if (!stack.isEmpty())
            {
                stack.pop();
                help.pop();
            }
        }

        public int top()
        {

            return stack.isEmpty() ? -1 : stack.peek();
        }

        public int getMin()
        {
            return help.isEmpty() ? -1 : help.peek();
        }
    }
}